package cn.com.zzl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;

/**
 * @description 登录servlet
 * @author 朱正磊
 * @date 2017年9月10日 下午10:13:06
 */
public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 3165028994159035737L;
	
	/**
	 * @description 处理POST请求，登录验证
	 * @param request 请求对象
	 * @param response 响应对象
	 * @throws ServletException Servlet异常
	 * @throws IOException IO流异常
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if (StringUtils.equals("张三", username) && StringUtils.equals("123456", password)) {
			request.setAttribute("value", "登录成功！");
			request.getRequestDispatcher("success.jsp").forward(request, response);
		} else {
			request.setAttribute("value", "用户名或密码输入错误！");
			request.getRequestDispatcher("error.jsp").forward(request, response);
		}
	}

}
